package com.newidea.jiangong.restful;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity<ApiResult<Object>> handleException(RuntimeException e) {
        log.error(e.getLocalizedMessage(), e);
        return ApiResult.build(
            HttpStatus.SERVICE_UNAVAILABLE,
            e.getMessage()
        );
    }
}
